home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Freeware
/
Read It Later 0.9924
/
read_it_later-0.9924-fx.xpi
/
chrome
/
isreaditlater.jar
/
content
/
ISRILpr.js
< prev
next >
Wrap
Text File
|
2008-10-28
|
3KB
|
133 lines
function ISRILpr() {
this.apiKey = 'readitlaterlist.com';
this.apiVersion = 1;
this.apiFormat = 'json';
this.apiUrl = 'http://api.postrank.com/v{VERSION}/postrank?appkey={APIKEY}&format={FORMAT}';
this.maxToSend = 30;
this.TOtime = 8;
}
ISRILpr.prototype = {
_init : function() {
this.xul = ISRILxul;
},
// --- //
start : function(force) {
if (!force && ISRILprefs.prefB('ask-aiderss')) {
ISRILpr.xul.MsgPostRankAsk(true);
return false;
} else {
if (force && ISRILpr.xul.bip('ListMsg-pr-ask').checked) {
ISRILprefs.setPref('ask-aiderss', false);
}
ISRILpr.xul.MsgPostRankAsk(false);
}
if (ISRILglobals.CacheStale || !ISRILpr.cache) {
ISRILpr.xul.ListMsgSet(true, 'Sorting');
var s = '';
var l = ISRIL.GetList( 12, false, false );
ISRILpr.urlTable = new Array();
for(var i in l) {
s += '&url[]='+l[i].uri;
ISRILpr.urlTable[l[i].uri] = l[i];
if (i == ISRILpr.maxToSend) { break; }
}
ISRILpr.query(s);
} else {
ISRILpr.xul.PopulateList( ISRILpr.filter( ISRILpr.cache ) );
}
},
// --- //
query : function(urls) {
var url = ISRILpr.url();
var ajax = new ISRILajax();
clearTimeout( ISRILpr.TO );
ISRILpr.TO = setTimeout('ISRILpr.timedOut()', ISRILpr.TOtime * 1000);
ajax.post(url, ISRILpr.callback, urls);
},
callback : function(r) {
try {
var results = ISRIL.json.decode(r);
var l = new Array();
clearTimeout( ISRILpr.TO );
var i = 0;
for(url in results) {
try {
l[i] = {
itemId : ISRILpr.urlTable[url].itemId,
title : ISRILpr.urlTable[url].title,
uri : ISRILpr.urlTable[url].uri,
tags : ISRILpr.urlTable[url].tags,
postrank : results[url].postrank,
postrank_color : results[url].postrank_color
}
i++;
} catch(err) {}
}
l.sort(ISRILpr.reSort);
ISRILpr.cache = l;
ISRILpr.xul.PopulateList( ISRILpr.filter(l) );
} catch(err) {
if ( ISRILpr.TO ) {
ISRILpr.timedOut();
}
}
},
// --- //
filter : function(l) {
ISRIL.resetCache();
var fL = new Object();
li = 0;
for(i in l) {
if (ISRIL.ProcessItem(l[i], ISRILpr.xul.Filter.value )) {
fL[li] = l[i];
li++;
}
}
return fL;
},
// --- //
timedOut : function() {
clearTimeout( ISRILpr.TO );
ISRILpr.xul.ListErrorSet(true, {txt:ISRIL.l('PostRankConnect'), onclk: ISRILpr.start, onCancel:"ISRILxul.bip('ListSort').selectedIndex = 1;ISRILxul.FillList();"} );
},
// --- //
url : function(format, key, version) {
var f = (format)?format:this.apiFormat;
var k = (key)?key:this.apiKey;
var v = (version)?version:this.apiVersion;
return ISRILpr.apiUrl.replace('{VERSION}',v).replace('{APIKEY}',k).replace('{FORMAT}',f);
},
reSort : function(a, b) {
var x = b.postrank;
var y = a.postrank;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
},
}
var ISRILpr = new ISRILpr();